package com.java.security.execption;

import com.java.security.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 异常处理器
 */
@RestControllerAdvice
@Slf4j
public class RRExceptionHandler {

    /**
     * 验证码为空的异常
     */
    @ExceptionHandler(AuthenticationServiceException.class)
    public R handleRRException(AuthenticationServiceException e) {
        e.printStackTrace();
        return R.error(e.getMessage());
    }

    /**
     * 处理自定义异常
     */
    @ExceptionHandler(RRException.class)
    public R handleRRException(RRException e) {
        e.printStackTrace();
        return R.error(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        log.error(e.getMessage());
        return R.error();
    }

}
